using InventoryIssue.API.Read.Application.Command.Allocate;
using InventoryIssue.Dtos;
using InventoryIssue.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Mvc;

namespace InventoryIssue.API.Read.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class TestAllocateRecordsController : ControllerBase
    {
        private readonly IMediator mediator;

        public TestAllocateRecordsController(IMediator mediator)
        {
            this.mediator = mediator;
        }

       

        

        /// <summary>
        /// 测试状态说明查询
        /// </summary>
        /// <param name="statusCode">状态代码</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> TestAllocateStatus(int statusCode = 0)
        {
            try
            {
                var request = new GetAllocateStatusCommand
                {
                    StatusCode = statusCode
                };
                var result = await mediator.Send(request);
                return Ok(result);
            }
            catch (Exception ex)
            {
                return BadRequest(new { error = ex.Message });
            }
        }

        /// <summary>
        /// 测试所有状态说明
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> TestAllStatuses()
        {
            try
            {
                var results = new List<AllocateStatusDto>();
                for (int i = 0; i <= 6; i++)
                {
                    var request = new GetAllocateStatusCommand
                    {
                        StatusCode = i
                    };
                    var result = await mediator.Send(request);
                    if (result.Data != null)
                    {
                        results.Add(result.Data);
                    }
                }
                return Ok(new { statuses = results });
            }
            catch (Exception ex)
            {
                return BadRequest(new { error = ex.Message });
            }
        }
    }
} 